package com.example.trackcircuitdiagnosis.controller;


import com.example.trackcircuitdiagnosis.entity.FaultTypeEntity;
import com.example.trackcircuitdiagnosis.service.FaultTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/faultType"})
public class FaultTypeController {
    @Autowired
    FaultTypeService faultTypeService;

    @GetMapping
    @ResponseBody
    public Map getFaultType(@RequestParam(required = false) Integer id) {
        Map<Object, Object> result = new HashMap<>();
        Map<Object, Object> data = new HashMap<>();
        if (id != null){
            FaultTypeEntity faultType = faultTypeService.selectById(id);
            switch (faultType.getDangerLevel()){
                case "1":faultType.setDangerLevel("一级报警");break;
                case "2":faultType.setDangerLevel("二级报警");break;
                case "3":faultType.setDangerLevel("三级报警");break;
                case "4":faultType.setDangerLevel("预警");break;
            }
            switch (faultType.getResult()){
                case "1":faultType.setResult("红光带");break;
                case "2":faultType.setResult("分路不良");break;
            }
            data.put("faultType", faultType);
        }else{
            List<FaultTypeEntity> faultTypes = faultTypeService.selectAll();
            data.put("faultTypes", faultTypes);
        }

        result.put("code", 20000);
        result.put("data", data);
        return result;
    }
//    @PutMapping
//    @ResponseBody
//    public Map updateFaultType(@RequestBody FaultType faultType) {
//
//        Map<Object, Object> result = new HashMap<>();
//        faultTypeService.update(faultType);
//        result.put("code", 20000);
//        return result;
//    }
//    @DeleteMapping
//    @ResponseBody
//    public Map updateFaultType(@RequestParam Integer id) {
//        Map<Object, Object> result = new HashMap<>();
//        Integer success = faultTypeService.delete(id);
//        result.put("code", 20000);
//        result.put("success", success);
//        return result;
//    }
}
